﻿using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Identity;

namespace OpenId2Ids
{
    /// <summary>
    /// 用户信息服务
    /// </summary>
    public class UserInfoService : ApplicationService
    {
        private IdentityUserManager _userManager;

        public UserInfoService(IdentityUserManager userManager)
        {
            _userManager = userManager;
        }

        /// <summary>
        /// 获取用户名
        /// </summary>
        public async Task<string> GetUserNameByIdAsync(Guid id)
        {
            try
            {
                var user = await _userManager.GetByIdAsync(id);
                return user.UserName;

            }
            catch (EntityNotFoundException)
            {
                throw new InvalidOperationException("用户不存在！");
            }
        }
    }
}
